package main

import (
	"fmt"
	"os"
)

func readFile(filename string) {
	//go语言一般会将错误码作为最后一个参数返回
	f1, err := os.Open(filename)
	//defer f1.Close()
	defer func() {
		fmt.Println("ready close file")
		f1.Close()
	}() //创建一个匿名函数，同时调用

	if err != nil {
		fmt.Println("open file var.go failed, err=!", err)
		return
	}

	defer fmt.Println("0000000")
	defer fmt.Println("1111111")
	defer fmt.Println("2222222")

	buf := make([]byte, 1024)
	n, _ := f1.Read(buf)
	fmt.Println("read file length:", n)
	fmt.Println("read file content: ", string(buf))

}

func main() {
	readFile("/home/uos/go/src/test/enum.go")
}
